/*
 This file 'Spinbox' is part of Firebird Integrated Solution 1.0

 Copyright (c) 2014 Lincong

 Contact:  
 Email: lincong1987@gmail.com

 QQ: 159257119

 See Usage at http://www.jplatformx.com/firebird

 Create date: 2014-06-19 16:01
 */

define(function (require, exports, module) {

	require("Firebird.ui.Component");
	require("../spinbox/js/jquery.spinbox");

	/**
	 * Firebird.ui.Spinbox
	 * @class Firebird.ui.Spinbox
	 */
	Firebird.define("Firebird.ui.Spinbox", {
		extend: "Firebird.ui.Component",
		statics: {
			_uuid: 1,
			uuid: function () {
				return this._uuid++;
			},
			attrs: function ($component) {
				return {
					renderTo: $component.get(0),
					// 实例ID, 可以在 context 里直接获取， var ins = context.getInstance("name");
					instanceId: $component.attr("fb-instance") || $component.attr("name") || $component.attr("id") || ("spinbox_" + Firebird.ui.FormHelper.uuid()),

					step: $component.attr("fb-step"),
					min: $component.attr("fb-min"),
					max: $component.attr("fb-max")
				};
			}
		},
		config: {
			renderTo: null,
			instanceId: null,

			step: null,
			min: null,
			max: null
		},
		/**
		 * defaults
		 * @returns {{value: undefined, max: undefined, min: undefined, step: number, decimal: boolean, precision: number, disabled: undefined, keyEnable: boolean, wheelEnable: boolean, autoRepeat: boolean, delay: number, interval: number, inputDisabledCls: string, width: undefined, wrapCls: string, activeCls: string, disabledCls: string, hoverCls: string, inputCls: string, btnWrapCls: string, btnWrapHoverCls: string, btnCls: string, downBtnCls: string, upBtnCls: string}}
		 */
		defaults: function (options) {
			return $.extend(true, {
				max: undefined,
				min: undefined,
				step: 1,
				decimal: false,
				precision: 2,
				disabled: undefined,
				keyEnable: false,
				wheelEnable: false,
				autoRepeat: true,
				delay: 400,
				interval: 80,
				inputDisabledCls: "ui-input-disabled",
				width: undefined,
				wrapCls: "ui-spinbox-wrap",
				activeCls: "ui-spinbox-active",
				disabledCls: "ui-spinbox-disabled",
				hoverCls: "ui-spinbox-hover",
				inputCls: "input-txt",
				btnWrapCls: "btn-wrap",
				btnWrapHoverCls: "btn-wrap-hover",
				btnCls: "btn",
				downBtnCls: "btn-down",
				upBtnCls: "btn-up"
			}, options || {});
		},
		_init: function () {
			var me = this;
			me.instance = $(me.getRenderTo());
			me.instance.data({
				instance: me,
				xtype: "spinbox"
			});

			me.options = $.extend({}, me.defaults(me.initialConfig));
			//me.instance.spinbox(me.options);

			// 拿到插件的实例
			//me.spinbox = $(me.id).data("_spinbox");
		},
		/**
		 *
		 * @returns {Firebird.ui.Spinbox}
		 */
		enable: function () {
			this.spinbox.enable();
			this._disabled = false;
			return this;
		},
		disable: function () {
			this.spinbox.disable();
			this._disabled = true;
			return this;
		},
		getValue: function () {
			return this.spinbox.getValue();
		},
		setValue: function (value) {
			this.spinbox.setValue(value);
			return this;
		},
		isDisabled: function () {
			return this.spinbox.isDisabled();
		}
	});

	module.exports = Firebird.ui.Spinbox;

});